<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The GRASP/AQUA Project, Glasgow University, 1993-1998

\section[WorkWrap]{Worker/wrapper-generating back-end of strictness analyser}
-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-8"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Core.Opt.WorkWrap</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwTopBinds"><span class="hs-identifier">wwTopBinds</span></a></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Arity.html"><span class="hs-identifier">GHC.Core.Opt.Arity</span></a></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Arity.html#manifestArity"><span class="hs-identifier">manifestArity</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.html"><span class="hs-identifier">GHC.Core</span></a></span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html"><span class="hs-identifier">GHC.Core.Unfold</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#certainlyWillInline"><span class="hs-identifier">certainlyWillInline</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkWwInlineRule"><span class="hs-identifier">mkWwInlineRule</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkWorkerUnfolding"><span class="hs-identifier">mkWorkerUnfolding</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html"><span class="hs-identifier">GHC.Core.Utils</span></a></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#exprType"><span class="hs-identifier">exprType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html#exprIsHNF"><span class="hs-identifier">exprIsHNF</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html"><span class="hs-identifier">GHC.Core.FVs</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#exprFreeVars"><span class="hs-identifier">exprFreeVars</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html"><span class="hs-identifier">GHC.Types.Id.Info</span></a></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html"><span class="hs-identifier">GHC.Types.Unique.Supply</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html"><span class="hs-identifier">GHC.Types.Demand</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Cpr.html"><span class="hs-identifier">GHC.Types.Cpr</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.Utils.html"><span class="hs-identifier">GHC.Core.Opt.WorkWrap.Utils</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html"><span class="hs-identifier">GHC.Core.FamInstEnv</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Monad.html"><span class="hs-identifier">GHC.Utils.Monad</span></a></span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-34"></span><span class="hs-comment">{-
We take Core bindings whose binders have:

\begin{enumerate}

\item Strictness attached (by the front-end of the strictness
analyser), and / or

\item Constructed Product Result information attached by the CPR
analysis pass.

\end{enumerate}

and we return some ``plain'' bindings which have been
worker/wrapper-ified, meaning:

\begin{enumerate}

\item Functions have been split into workers and wrappers where
appropriate.  If a function has both strictness and CPR properties
then only one worker/wrapper doing both transformations is produced;

\item Binders' @IdInfos@ have been updated to reflect the existence of
these workers/wrappers (this is where we get STRICTNESS and CPR pragma
info for exported values).
\end{enumerate}
-}</span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwTopBinds"><span class="hs-identifier hs-type">wwTopBinds</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html#UniqSupply"><span class="hs-identifier hs-type">UniqSupply</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreProgram"><span class="hs-identifier hs-type">CoreProgram</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreProgram"><span class="hs-identifier hs-type">CoreProgram</span></a></span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span id="wwTopBinds"><span class="annot"><span class="annottext">wwTopBinds :: DynFlags -&gt; FamInstEnvs -&gt; UniqSupply -&gt; CoreProgram -&gt; CoreProgram
</span><a href="GHC.Core.Opt.WorkWrap.html#wwTopBinds"><span class="hs-identifier hs-var hs-var">wwTopBinds</span></a></span></span><span> </span><span id="local-6989586621680963565"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963565"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963564"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963564"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621680963563"><span class="annot"><span class="annottext">UniqSupply
</span><a href="#local-6989586621680963563"><span class="hs-identifier hs-var">us</span></a></span></span><span> </span><span id="local-6989586621680963562"><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680963562"><span class="hs-identifier hs-var">top_binds</span></a></span></span><span>
</span><span id="line-65"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UniqSupply -&gt; UniqSM CoreProgram -&gt; CoreProgram
forall a. UniqSupply -&gt; UniqSM a -&gt; a
</span><a href="GHC.Types.Unique.Supply.html#initUs_"><span class="hs-identifier hs-var">initUs_</span></a></span><span> </span><span class="annot"><span class="annottext">UniqSupply
</span><a href="#local-6989586621680963563"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="annot"><span class="annottext">(UniqSM CoreProgram -&gt; CoreProgram)
-&gt; UniqSM CoreProgram -&gt; CoreProgram
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-66"></span><span>    </span><span id="local-6989586621680963560"><span class="annot"><span class="annottext">[CoreProgram]
</span><a href="#local-6989586621680963560"><span class="hs-identifier hs-var">top_binds'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(CoreBind -&gt; UniqSM CoreProgram)
-&gt; CoreProgram -&gt; UniqSM [CoreProgram]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; CoreBind -&gt; UniqSM CoreProgram
</span><a href="GHC.Core.Opt.WorkWrap.html#wwBind"><span class="hs-identifier hs-var">wwBind</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963565"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963564"><span class="hs-identifier hs-var">fam_envs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680963562"><span class="hs-identifier hs-var">top_binds</span></a></span><span>
</span><span id="line-67"></span><span>    </span><span class="annot"><span class="annottext">CoreProgram -&gt; UniqSM CoreProgram
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreProgram] -&gt; CoreProgram
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreProgram]
</span><a href="#local-6989586621680963560"><span class="hs-identifier hs-var">top_binds'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection[wwBind-wwExpr]{@wwBind@ and @wwExpr@}
*                                                                      *
************************************************************************

@wwBind@ works on a binding, trying each \tr{(binder, expr)} pair in
turn.  Non-recursive case first, then recursive...
-}</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwBind"><span class="hs-identifier hs-type">wwBind</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-81"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span>
</span><span id="line-82"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreBind"><span class="hs-identifier hs-type">CoreBind</span></a></span><span>
</span><span id="line-83"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html#UniqSM"><span class="hs-identifier hs-type">UniqSM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreBind"><span class="hs-identifier hs-type">CoreBind</span></a></span><span class="hs-special">]</span><span>    </span><span class="hs-comment">-- returns a WwBinding intermediate form;</span><span>
</span><span id="line-84"></span><span>                                </span><span class="hs-comment">-- the caller will convert to Expr/Binding,</span><span>
</span><span id="line-85"></span><span>                                </span><span class="hs-comment">-- as appropriate.</span><span>
</span><span id="line-86"></span><span>
</span><span id="line-87"></span><span id="wwBind"><span class="annot"><span class="annottext">wwBind :: DynFlags -&gt; FamInstEnvs -&gt; CoreBind -&gt; UniqSM CoreProgram
</span><a href="GHC.Core.Opt.WorkWrap.html#wwBind"><span class="hs-identifier hs-var hs-var">wwBind</span></a></span></span><span> </span><span id="local-6989586621680963556"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963556"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963555"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963555"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span id="local-6989586621680963553"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963553"><span class="hs-identifier hs-var">binder</span></a></span></span><span> </span><span id="local-6989586621680963552"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963552"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-88"></span><span>    </span><span id="local-6989586621680963551"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963551"><span class="hs-identifier hs-var">new_rhs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963556"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963555"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963552"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-89"></span><span>    </span><span id="local-6989586621680963549"><span class="annot"><span class="annottext">[(Var, Expr Var)]
</span><a href="#local-6989586621680963549"><span class="hs-identifier hs-var">new_pairs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; FamInstEnvs
-&gt; RecFlag
-&gt; Var
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#tryWW"><span class="hs-identifier hs-var">tryWW</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963556"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963555"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">RecFlag
</span><a href="GHC.Types.Basic.html#NonRecursive"><span class="hs-identifier hs-var">NonRecursive</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963553"><span class="hs-identifier hs-var">binder</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963551"><span class="hs-identifier hs-var">new_rhs</span></a></span><span>
</span><span id="line-90"></span><span>    </span><span class="annot"><span class="annottext">CoreProgram -&gt; UniqSM CoreProgram
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Var -&gt; Expr Var -&gt; CoreBind
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963546"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963545"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680963546"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963546"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680963545"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963545"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)]
</span><a href="#local-6989586621680963549"><span class="hs-identifier hs-var">new_pairs</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-91"></span><span>      </span><span class="hs-comment">-- Generated bindings must be non-recursive</span><span>
</span><span id="line-92"></span><span>      </span><span class="hs-comment">-- because the original binding was.</span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwBind"><span class="hs-identifier hs-var">wwBind</span></a></span><span> </span><span id="local-6989586621680963544"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963544"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963543"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963543"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-type">Rec</span></a></span><span> </span><span id="local-6989586621680963541"><span class="annot"><span class="annottext">[(Var, Expr Var)]
</span><a href="#local-6989586621680963541"><span class="hs-identifier hs-var">pairs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-95"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; CoreProgram
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreBind -&gt; CoreProgram)
-&gt; ([(Var, Expr Var)] -&gt; CoreBind)
-&gt; [(Var, Expr Var)]
-&gt; CoreProgram
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)] -&gt; CoreBind
forall b. [(b, Expr b)] -&gt; Bind b
</span><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-var">Rec</span></a></span><span> </span><span class="annot"><span class="annottext">([(Var, Expr Var)] -&gt; CoreProgram)
-&gt; UniqSM [(Var, Expr Var)] -&gt; UniqSM CoreProgram
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">((Var, Expr Var) -&gt; UniqSM [(Var, Expr Var)])
-&gt; [(Var, Expr Var)] -&gt; UniqSM [(Var, Expr Var)]
forall (m :: * -&gt; *) a b. Monad m =&gt; (a -&gt; m [b]) -&gt; [a] -&gt; m [b]
</span><a href="GHC.Utils.Monad.html#concatMapM"><span class="hs-identifier hs-var">concatMapM</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, Expr Var) -&gt; UniqSM [(Var, Expr Var)]
</span><a href="#local-6989586621680963537"><span class="hs-identifier hs-var">do_one</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)]
</span><a href="#local-6989586621680963541"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-96"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-97"></span><span>    </span><span id="local-6989586621680963537"><span class="annot"><span class="annottext">do_one :: (Var, Expr Var) -&gt; UniqSM [(Var, Expr Var)]
</span><a href="#local-6989586621680963537"><span class="hs-identifier hs-var hs-var">do_one</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680963535"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963535"><span class="hs-identifier hs-var">binder</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680963534"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963534"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680963533"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963533"><span class="hs-identifier hs-var">new_rhs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963544"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963543"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963534"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-98"></span><span>                              </span><span class="annot"><span class="annottext">DynFlags
-&gt; FamInstEnvs
-&gt; RecFlag
-&gt; Var
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#tryWW"><span class="hs-identifier hs-var">tryWW</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963544"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963543"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">RecFlag
</span><a href="GHC.Types.Basic.html#Recursive"><span class="hs-identifier hs-var">Recursive</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963535"><span class="hs-identifier hs-var">binder</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963533"><span class="hs-identifier hs-var">new_rhs</span></a></span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span class="hs-comment">{-
@wwExpr@ basically just walks the tree, looking for appropriate
annotations that can be used. Remember it is @wwBind@ that does the
matching by looking for strict arguments of the correct type.
@wwExpr@ is a version that just returns the ``Plain'' Tree.
-}</span><span>
</span><span id="line-106"></span><span>
</span><span id="line-107"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-type">wwExpr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html#UniqSM"><span class="hs-identifier hs-type">UniqSM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span id="wwExpr"><span class="annot"><span class="annottext">wwExpr :: DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var hs-var">wwExpr</span></a></span></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span>      </span><span class="annot"><span class="annottext">FamInstEnvs
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680963530"><span class="annot"><span class="annottext">e :: Expr Var
</span><a href="#local-6989586621680963530"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; UniqSM (Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963530"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-110"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span>      </span><span class="annot"><span class="annottext">FamInstEnvs
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680963528"><span class="annot"><span class="annottext">e :: Expr Var
</span><a href="#local-6989586621680963528"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; UniqSM (Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963528"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-111"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span>      </span><span class="annot"><span class="annottext">FamInstEnvs
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680963526"><span class="annot"><span class="annottext">e :: Expr Var
</span><a href="#local-6989586621680963526"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span>  </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; UniqSM (Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963526"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-112"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span>      </span><span class="annot"><span class="annottext">FamInstEnvs
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680963524"><span class="annot"><span class="annottext">e :: Expr Var
</span><a href="#local-6989586621680963524"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span>  </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; UniqSM (Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963524"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-113"></span><span>
</span><span id="line-114"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span id="local-6989586621680963522"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963522"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963521"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963521"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680963519"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963519"><span class="hs-identifier hs-var">binder</span></a></span></span><span> </span><span id="local-6989586621680963518"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963518"><span class="hs-identifier hs-var">expr</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Expr Var -&gt; Expr Var
forall b. b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-var">Lam</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963517"><span class="hs-identifier hs-var">new_binder</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr Var -&gt; Expr Var) -&gt; UniqSM (Expr Var) -&gt; UniqSM (Expr Var)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963522"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963521"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963518"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-116"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621680963517"><span class="annot"><span class="annottext">new_binder :: Var
</span><a href="#local-6989586621680963517"><span class="hs-identifier hs-var hs-var">new_binder</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963519"><span class="hs-identifier hs-var">binder</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Var
</span><a href="GHC.Types.Id.html#zapIdUsedOnceInfo"><span class="hs-identifier hs-var">zapIdUsedOnceInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963519"><span class="hs-identifier hs-var">binder</span></a></span><span>
</span><span id="line-117"></span><span>                   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963519"><span class="hs-identifier hs-var">binder</span></a></span><span>
</span><span id="line-118"></span><span>  </span><span class="hs-comment">-- See Note [Zapping Used Once info in WorkWrap]</span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span id="local-6989586621680963514"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963514"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963513"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963513"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680963511"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963511"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680963510"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963510"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; Expr Var -&gt; Expr Var
forall b. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#App"><span class="hs-identifier hs-var">App</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr Var -&gt; Expr Var -&gt; Expr Var)
-&gt; UniqSM (Expr Var) -&gt; UniqSM (Expr Var -&gt; Expr Var)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963514"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963513"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963511"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">UniqSM (Expr Var -&gt; Expr Var)
-&gt; UniqSM (Expr Var) -&gt; UniqSM (Expr Var)
forall (f :: * -&gt; *) a b. Applicative f =&gt; f (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var">&lt;*&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963514"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963513"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963510"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-122"></span><span>
</span><span id="line-123"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span id="local-6989586621680963509"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963509"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963508"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963508"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680963506"><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680963506"><span class="hs-identifier hs-var">note</span></a></span></span><span> </span><span id="local-6989586621680963505"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963505"><span class="hs-identifier hs-var">expr</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-124"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; Expr Var -&gt; Expr Var
forall b. Tickish Var -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-var">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680963506"><span class="hs-identifier hs-var">note</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr Var -&gt; Expr Var) -&gt; UniqSM (Expr Var) -&gt; UniqSM (Expr Var)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963509"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963508"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963505"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-125"></span><span>
</span><span id="line-126"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span id="local-6989586621680963504"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963504"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963503"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963503"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680963501"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963501"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span id="local-6989586621680963500"><span class="annot"><span class="annottext">CoercionR
</span><a href="#local-6989586621680963500"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-127"></span><span>    </span><span id="local-6989586621680963499"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963499"><span class="hs-identifier hs-var">new_expr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963504"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963503"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963501"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-128"></span><span>    </span><span class="annot"><span class="annottext">Expr Var -&gt; UniqSM (Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Var -&gt; CoercionR -&gt; Expr Var
forall b. Expr b -&gt; CoercionR -&gt; Expr b
</span><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-var">Cast</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963499"><span class="hs-identifier hs-var">new_expr</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionR
</span><a href="#local-6989586621680963500"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-129"></span><span>
</span><span id="line-130"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span id="local-6989586621680963498"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963498"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963497"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963497"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span id="local-6989586621680963495"><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680963495"><span class="hs-identifier hs-var">bind</span></a></span></span><span> </span><span id="local-6989586621680963494"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963494"><span class="hs-identifier hs-var">expr</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-131"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreProgram -&gt; Expr Var -&gt; Expr Var
forall b. [Bind b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLets"><span class="hs-identifier hs-var">mkLets</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreProgram -&gt; Expr Var -&gt; Expr Var)
-&gt; UniqSM CoreProgram -&gt; UniqSM (Expr Var -&gt; Expr Var)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; CoreBind -&gt; UniqSM CoreProgram
</span><a href="GHC.Core.Opt.WorkWrap.html#wwBind"><span class="hs-identifier hs-var">wwBind</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963498"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963497"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreBind
</span><a href="#local-6989586621680963495"><span class="hs-identifier hs-var">bind</span></a></span><span> </span><span class="annot"><span class="annottext">UniqSM (Expr Var -&gt; Expr Var)
-&gt; UniqSM (Expr Var) -&gt; UniqSM (Expr Var)
forall (f :: * -&gt; *) a b. Applicative f =&gt; f (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var">&lt;*&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963498"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963497"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963494"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-132"></span><span>
</span><span id="line-133"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span id="local-6989586621680963492"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963492"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963491"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963491"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680963489"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963489"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span id="local-6989586621680963488"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963488"><span class="hs-identifier hs-var">binder</span></a></span></span><span> </span><span id="local-6989586621680963487"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680963487"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span id="local-6989586621680963486"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680963486"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-134"></span><span>    </span><span id="local-6989586621680963485"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963485"><span class="hs-identifier hs-var">new_expr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963492"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963491"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963489"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-135"></span><span>    </span><span id="local-6989586621680963484"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680963484"><span class="hs-identifier hs-var">new_alts</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Alt Var -&gt; UniqSM (Alt Var)) -&gt; [Alt Var] -&gt; UniqSM [Alt Var]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="annot"><span class="annottext">Alt Var -&gt; UniqSM (Alt Var)
forall {a}. (a, [Var], Expr Var) -&gt; UniqSM (a, [Var], Expr Var)
</span><a href="#local-6989586621680963483"><span class="hs-identifier hs-var">ww_alt</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680963486"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-136"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680963482"><span class="annot"><span class="annottext">new_binder :: Var
</span><a href="#local-6989586621680963482"><span class="hs-identifier hs-var hs-var">new_binder</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Var
</span><a href="GHC.Types.Id.html#zapIdUsedOnceInfo"><span class="hs-identifier hs-var">zapIdUsedOnceInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963488"><span class="hs-identifier hs-var">binder</span></a></span><span>
</span><span id="line-137"></span><span>      </span><span class="hs-comment">-- See Note [Zapping Used Once info in WorkWrap]</span><span>
</span><span id="line-138"></span><span>    </span><span class="annot"><span class="annottext">Expr Var -&gt; UniqSM (Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Var -&gt; Var -&gt; Type -&gt; [Alt Var] -&gt; Expr Var
forall b. Expr b -&gt; b -&gt; Type -&gt; [Alt b] -&gt; Expr b
</span><a href="GHC.Core.html#Case"><span class="hs-identifier hs-var">Case</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963485"><span class="hs-identifier hs-var">new_expr</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963482"><span class="hs-identifier hs-var">new_binder</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680963487"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680963484"><span class="hs-identifier hs-var">new_alts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-139"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-140"></span><span>    </span><span id="local-6989586621680963483"><span class="annot"><span class="annottext">ww_alt :: (a, [Var], Expr Var) -&gt; UniqSM (a, [Var], Expr Var)
</span><a href="#local-6989586621680963483"><span class="hs-identifier hs-var hs-var">ww_alt</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680963479"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680963479"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680963478"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680963478"><span class="hs-identifier hs-var">binders</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680963477"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963477"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-141"></span><span>        </span><span id="local-6989586621680963476"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963476"><span class="hs-identifier hs-var">new_rhs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; Expr Var -&gt; UniqSM (Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.html#wwExpr"><span class="hs-identifier hs-var">wwExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963492"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963491"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963477"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-142"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680963475"><span class="annot"><span class="annottext">new_binders :: [Var]
</span><a href="#local-6989586621680963475"><span class="hs-identifier hs-var hs-var">new_binders</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963474"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Var
</span><a href="GHC.Types.Id.html#zapIdUsedOnceInfo"><span class="hs-identifier hs-var">zapIdUsedOnceInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963474"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963474"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-143"></span><span>                          </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680963474"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963474"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680963478"><span class="hs-identifier hs-var">binders</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-144"></span><span>           </span><span class="hs-comment">-- See Note [Zapping Used Once info in WorkWrap]</span><span>
</span><span id="line-145"></span><span>        </span><span class="annot"><span class="annottext">(a, [Var], Expr Var) -&gt; UniqSM (a, [Var], Expr Var)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680963479"><span class="hs-identifier hs-var">con</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680963475"><span class="hs-identifier hs-var">new_binders</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963476"><span class="hs-identifier hs-var">new_rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-146"></span><span>
</span><span id="line-147"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection[tryWW]{@tryWW@: attempt a worker/wrapper pair}
*                                                                      *
************************************************************************

@tryWW@ just accumulates arguments, converts strictness info from the
front-end into the proper form, then calls @mkWwBodies@ to do
the business.

The only reason this is monadised is for the unique supply.

Note [Don't w/w INLINE things]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's very important to refrain from w/w-ing an INLINE function (ie one
with a stable unfolding) because the wrapper will then overwrite the
old stable unfolding with the wrapper code.

Furthermore, if the programmer has marked something as INLINE,
we may lose by w/w'ing it.

If the strictness analyser is run twice, this test also prevents
wrappers (which are INLINEd) from being re-done.  (You can end up with
several liked-named Ids bouncing around at the same time---absolute
mischief.)

Notice that we refrain from w/w'ing an INLINE function even if it is
in a recursive group.  It might not be the loop breaker.  (We could
test for loop-breaker-hood, but I'm not sure that ever matters.)

Note [Worker-wrapper for INLINABLE functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we have
  {-# INLINABLE f #-}
  f :: Ord a =&gt; [a] -&gt; Int -&gt; a
  f x y = ....f....

where f is strict in y, we might get a more efficient loop by w/w'ing
f.  But that would make a new unfolding which would overwrite the old
one! So the function would no longer be INLNABLE, and in particular
will not be specialised at call sites in other modules.

This comes in practice (#6056).

Solution: do the w/w for strictness analysis, but transfer the Stable
unfolding to the *worker*.  So we will get something like this:

  {-# INLINE[0] f #-}
  f :: Ord a =&gt; [a] -&gt; Int -&gt; a
  f d x y = case y of I# y' -&gt; fw d x y'

  {-# INLINABLE[0] fw #-}
  fw :: Ord a =&gt; [a] -&gt; Int# -&gt; a
  fw d x y' = let y = I# y' in ...f...

How do we &quot;transfer the unfolding&quot;? Easy: by using the old one, wrapped
in work_fn! See GHC.Core.Unfold.mkWorkerUnfolding.

Note [Worker-wrapper for NOINLINE functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We used to disable worker/wrapper for NOINLINE things, but it turns out
this can cause unnecessary reboxing of values. Consider

  {-# NOINLINE f #-}
  f :: Int -&gt; a
  f x = error (show x)

  g :: Bool -&gt; Bool -&gt; Int -&gt; Int
  g True  True  p = f p
  g False True  p = p + 1
  g b     False p = g b True p

the strictness analysis will discover f and g are strict, but because f
has no wrapper, the worker for g will rebox p. So we get

  $wg x y p# =
    let p = I# p# in  -- Yikes! Reboxing!
    case x of
      False -&gt;
        case y of
          False -&gt; $wg False True p#
          True -&gt; +# p# 1#
      True -&gt;
        case y of
          False -&gt; $wg True True p#
          True -&gt; case f p of { }

  g x y p = case p of (I# p#) -&gt; $wg x y p#

Now, in this case the reboxing will float into the True branch, and so
the allocation will only happen on the error path. But it won't float
inwards if there are multiple branches that call (f p), so the reboxing
will happen on every call of g. Disaster.

Solution: do worker/wrapper even on NOINLINE things; but move the
NOINLINE pragma to the worker.

(See #13143 for a real-world example.)

It is crucial that we do this for *all* NOINLINE functions. #10069
demonstrates what happens when we promise to w/w a (NOINLINE) leaf
function, but fail to deliver:

  data C = C Int# Int#

  {-# NOINLINE c1 #-}
  c1 :: C -&gt; Int#
  c1 (C _ n) = n

  {-# NOINLINE fc #-}
  fc :: C -&gt; Int#
  fc c = 2 *# c1 c

Failing to w/w `c1`, but still w/wing `fc` leads to the following code:

  c1 :: C -&gt; Int#
  c1 (C _ n) = n

  $wfc :: Int# -&gt; Int#
  $wfc n = let c = C 0# n in 2 #* c1 c

  fc :: C -&gt; Int#
  fc (C _ n) = $wfc n

Yikes! The reboxed `C` in `$wfc` can't cancel out, so we are in a bad place.
This generalises to any function that derives its strictness signature from
its callees, so we have to make sure that when a function announces particular
strictness properties, we have to w/w them accordingly, even if it means
splitting a NOINLINE function.

Note [Worker activation]
~~~~~~~~~~~~~~~~~~~~~~~~
Follows on from Note [Worker-wrapper for INLINABLE functions]

It is *vital* that if the worker gets an INLINABLE pragma (from the
original function), then the worker has the same phase activation as
the wrapper (or later).  That is necessary to allow the wrapper to
inline into the worker's unfolding: see GHC.Core.Opt.Simplify.Utils
Note [Simplifying inside stable unfoldings].

If the original is NOINLINE, it's important that the work inherit the
original activation. Consider

  {-# NOINLINE expensive #-}
  expensive x = x + 1

  f y = let z = expensive y in ...

If expensive's worker inherits the wrapper's activation,
we'll get this (because of the compromise in point (2) of
Note [Wrapper activation])

  {-# NOINLINE[0] $wexpensive #-}
  $wexpensive x = x + 1
  {-# INLINE[0] expensive #-}
  expensive x = $wexpensive x

  f y = let z = expensive y in ...

and $wexpensive will be immediately inlined into expensive, followed by
expensive into f. This effectively removes the original NOINLINE!

Otherwise, nothing is lost by giving the worker the same activation as the
wrapper, because the worker won't have any chance of inlining until the
wrapper does; there's no point in giving it an earlier activation.

Note [Don't w/w inline small non-loop-breaker things]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In general, we refrain from w/w-ing *small* functions, which are not
loop breakers, because they'll inline anyway.  But we must take care:
it may look small now, but get to be big later after other inlining
has happened.  So we take the precaution of adding an INLINE pragma to
any such functions.

I made this change when I observed a big function at the end of
compilation with a useful strictness signature but no w-w.  (It was
small during demand analysis, we refrained from w/w, and then got big
when something was inlined in its rhs.) When I measured it on nofib,
it didn't make much difference; just a few percent improved allocation
on one benchmark (bspt/Euclid.space).  But nothing got worse.

There is an infelicity though.  We may get something like
      f = g val
==&gt;
      g x = case gw x of r -&gt; I# r

      f {- InlineStable, Template = g val -}
      f = case gw x of r -&gt; I# r

The code for f duplicates that for g, without any real benefit. It
won't really be executed, because calls to f will go via the inlining.

Note [Don't w/w join points for CPR]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There's no point in exploiting CPR info on a join point. If the whole function
is getting CPR'd, then the case expression around the worker function will get
pushed into the join point by the simplifier, which will have the same effect
that w/w'ing for CPR would have - the result will be returned in an unboxed
tuple.

  f z = let join j x y = (x+1, y+1)
        in case z of A -&gt; j 1 2
                     B -&gt; j 2 3

  =&gt;

  f z = case $wf z of (# a, b #) -&gt; (a, b)
  $wf z = case (let join j x y = (x+1, y+1)
                in case z of A -&gt; j 1 2
                             B -&gt; j 2 3) of (a, b) -&gt; (# a, b #)

  =&gt;

  f z = case $wf z of (# a, b #) -&gt; (a, b)
  $wf z = let join j x y = (# x+1, y+1 #)
          in case z of A -&gt; j 1 2
                       B -&gt; j 2 3

Note that we still want to give @j@ the CPR property, so that @f@ has it. So
CPR *analyse* join points as regular functions, but don't *transform* them.

Doing W/W for returned products on a join point would be tricky anyway, as the
worker could not be a join point because it would not be tail-called. However,
doing the *argument* part of W/W still works for join points, since the wrapper
body will make a tail call:

  f z = let join j x y = x + y
        in ...

  =&gt;

  f z = let join $wj x# y# = x# +# y#
                 j x y = case x of I# x# -&gt;
                         case y of I# y# -&gt;
                         $wj x# y#
        in ...

Note [Wrapper activation]
~~~~~~~~~~~~~~~~~~~~~~~~~
When should the wrapper inlining be active?

1. It must not be active earlier than the current Activation of the
   Id

2. It should be active at some point, despite (1) because of
   Note [Worker-wrapper for NOINLINE functions]

3. For ordinary functions with no pragmas we want to inline the
   wrapper as early as possible (#15056).  Suppose another module
   defines    f x = g x x
   and suppose there is some RULE for (g True True).  Then if we have
   a call (f True), we'd expect to inline 'f' and the RULE will fire.
   But if f is w/w'd (which it might be), we want the inlining to
   occur just as if it hadn't been.

   (This only matters if f's RHS is big enough to w/w, but small
   enough to inline given the call site, but that can happen.)

4. We do not want to inline the wrapper before specialisation.
         module Foo where
           f :: Num a =&gt; a -&gt; Int -&gt; a
           f n 0 = n              -- Strict in the Int, hence wrapper
           f n x = f (n+n) (x-1)

           g :: Int -&gt; Int
           g x = f x x            -- Provokes a specialisation for f

         module Bar where
           import Foo

           h :: Int -&gt; Int
           h x = f 3 x

   In module Bar we want to give specialisations a chance to fire
   before inlining f's wrapper.

   Historical note: At one stage I tried making the wrapper inlining
   always-active, and that had a very bad effect on nofib/imaginary/x2n1;
   a wrapper was inlined before the specialisation fired.

Reminder: Note [Don't w/w INLINE things], so we don't need to worry
          about INLINE things here.

Conclusion:
  - If the user said NOINLINE[n], respect that

  - If the user said NOINLINE, inline the wrapper only after
    phase 0, the last user-visible phase.  That means that all
    rules will have had a chance to fire.

    What phase is after phase 0?  Answer: FinalPhase, that's the reason it
    exists. NB: Similar to InitialPhase, users can't write INLINE[Final] f;
    it's syntactically illegal.

  - Otherwise inline wrapper in phase 2.  That allows the
    'gentle' simplification pass to apply specialisation rules


Note [Wrapper NoUserInline]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The use an inl_inline of NoUserInline on the wrapper distinguishes
this pragma from one that was given by the user. In particular, CSE
will not happen if there is a user-specified pragma, but should happen
for w/w&#8217;ed things (#14186).
-}</span><span>
</span><span id="line-453"></span><span>
</span><span id="line-454"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#tryWW"><span class="hs-identifier hs-type">tryWW</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-455"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span>
</span><span id="line-456"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#RecFlag"><span class="hs-identifier hs-type">RecFlag</span></a></span><span>
</span><span id="line-457"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>                           </span><span class="hs-comment">-- The fn binder</span><span>
</span><span id="line-458"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>                     </span><span class="hs-comment">-- The bound rhs; its innards</span><span>
</span><span id="line-459"></span><span>                                        </span><span class="hs-comment">--   are already ww'd</span><span>
</span><span id="line-460"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html#UniqSM"><span class="hs-identifier hs-type">UniqSM</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>      </span><span class="hs-comment">-- either *one* or *two* pairs;</span><span>
</span><span id="line-461"></span><span>                                        </span><span class="hs-comment">-- if one, then no worker (only</span><span>
</span><span id="line-462"></span><span>                                        </span><span class="hs-comment">-- the orig &quot;wrapper&quot; lives on);</span><span>
</span><span id="line-463"></span><span>                                        </span><span class="hs-comment">-- if two, then a worker and a</span><span>
</span><span id="line-464"></span><span>                                        </span><span class="hs-comment">-- wrapper.</span><span>
</span><span id="line-465"></span><span id="tryWW"><span class="annot"><span class="annottext">tryWW :: DynFlags
-&gt; FamInstEnvs
-&gt; RecFlag
-&gt; Var
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#tryWW"><span class="hs-identifier hs-var hs-var">tryWW</span></a></span></span><span> </span><span id="local-6989586621680963472"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963472"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963471"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963471"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621680963470"><span class="annot"><span class="annottext">RecFlag
</span><a href="#local-6989586621680963470"><span class="hs-identifier hs-var">is_rec</span></a></span></span><span> </span><span id="local-6989586621680963469"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span></span><span> </span><span id="local-6989586621680963468"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-466"></span><span>  </span><span class="hs-comment">-- See Note [Worker-wrapper for NOINLINE functions]</span><span>
</span><span id="line-467"></span><span>
</span><span id="line-468"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680963467"><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680963467"><span class="hs-identifier hs-var">stable_unf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IdInfo -&gt; Maybe Unfolding
</span><a href="GHC.Core.Unfold.html#certainlyWillInline"><span class="hs-identifier hs-var">certainlyWillInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963472"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963466"><span class="hs-identifier hs-var">fn_info</span></a></span><span>
</span><span id="line-469"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)] -&gt; UniqSM [(Var, Expr Var)]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; Unfolding -&gt; Var
</span><a href="GHC.Types.Id.html#setIdUnfolding"><span class="hs-operator hs-var">`setIdUnfolding`</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680963467"><span class="hs-identifier hs-var">stable_unf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-470"></span><span>        </span><span class="hs-comment">-- See Note [Don't w/w INLINE things]</span><span>
</span><span id="line-471"></span><span>        </span><span class="hs-comment">-- See Note [Don't w/w inline small non-loop-breaker things]</span><span>
</span><span id="line-472"></span><span>
</span><span id="line-473"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680963464"><span class="hs-identifier hs-var">is_fun</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680963462"><span class="hs-identifier hs-var">is_eta_exp</span></a></span><span>
</span><span id="line-474"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; FamInstEnvs
-&gt; Var
-&gt; IdInfo
-&gt; [Demand]
-&gt; Divergence
-&gt; CprResult
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#splitFun"><span class="hs-identifier hs-var">splitFun</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963472"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963471"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963460"><span class="hs-identifier hs-var">new_fn_id</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963466"><span class="hs-identifier hs-var">fn_info</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680963459"><span class="hs-identifier hs-var">wrap_dmds</span></a></span><span> </span><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680963458"><span class="hs-identifier hs-var">div</span></a></span><span> </span><span class="annot"><span class="annottext">CprResult
</span><a href="#local-6989586621680963457"><span class="hs-identifier hs-var">cpr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-475"></span><span>
</span><span id="line-476"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680963456"><span class="hs-identifier hs-var">is_thunk</span></a></span><span>                                   </span><span class="hs-comment">-- See Note [Thunk splitting]</span><span>
</span><span id="line-477"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; FamInstEnvs
-&gt; RecFlag
-&gt; Var
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#splitThunk"><span class="hs-identifier hs-var">splitThunk</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963472"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963471"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">RecFlag
</span><a href="#local-6989586621680963470"><span class="hs-identifier hs-var">is_rec</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963460"><span class="hs-identifier hs-var">new_fn_id</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-478"></span><span>
</span><span id="line-479"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-480"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)] -&gt; UniqSM [(Var, Expr Var)]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963460"><span class="hs-identifier hs-var">new_fn_id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-481"></span><span>
</span><span id="line-482"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-483"></span><span>    </span><span id="local-6989586621680963466"><span class="annot"><span class="annottext">fn_info :: IdInfo
</span><a href="#local-6989586621680963466"><span class="hs-identifier hs-var hs-var">fn_info</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Var -&gt; IdInfo
Var -&gt; IdInfo
</span><a href="GHC.Types.Var.html#idInfo"><span class="hs-identifier hs-var">idInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span><span>
</span><span id="line-484"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680963459"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680963459"><span class="hs-identifier hs-var">wrap_dmds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680963458"><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680963458"><span class="hs-identifier hs-var">div</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StrictSig -&gt; ([Demand], Divergence)
</span><a href="GHC.Types.Demand.html#splitStrictSig"><span class="hs-identifier hs-var">splitStrictSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdInfo -&gt; StrictSig
</span><a href="GHC.Types.Id.Info.html#strictnessInfo"><span class="hs-identifier hs-var hs-var">strictnessInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963466"><span class="hs-identifier hs-var">fn_info</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-485"></span><span>
</span><span id="line-486"></span><span>    </span><span id="local-6989586621680963449"><span class="annot"><span class="annottext">cpr_ty :: CprType
</span><a href="#local-6989586621680963449"><span class="hs-identifier hs-var hs-var">cpr_ty</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CprSig -&gt; CprType
</span><a href="GHC.Types.Cpr.html#getCprSig"><span class="hs-identifier hs-var hs-var">getCprSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdInfo -&gt; CprSig
</span><a href="GHC.Types.Id.Info.html#cprInfo"><span class="hs-identifier hs-var hs-var">cprInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963466"><span class="hs-identifier hs-var">fn_info</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-487"></span><span>    </span><span class="hs-comment">-- Arity of the CPR sig should match idArity when it's not a join point.</span><span>
</span><span id="line-488"></span><span>    </span><span class="hs-comment">-- See Note [Arity trimming for CPR signatures] in GHC.Core.Opt.CprAnal</span><span>
</span><span id="line-489"></span><span>    </span><span id="local-6989586621680963457"><span class="annot"><span class="annottext">cpr :: CprResult
</span><a href="#local-6989586621680963457"><span class="hs-identifier hs-var hs-var">cpr</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isJoinId</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-identifier">cpr_ty</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">topCprType</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-identifier">ct_arty</span><span> </span><span class="hs-identifier">cpr_ty</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">arityInfo</span><span> </span><span class="hs-identifier">fn_info</span><span>
</span><span id="line-490"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-operator">&lt;&gt;</span><span> </span><span class="hs-identifier">colon</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">text</span><span> </span><span class="hs-string">&quot;ct_arty:&quot;</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">int</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ct_arty</span><span> </span><span class="hs-identifier">cpr_ty</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">text</span><span> </span><span class="hs-string">&quot;arityInfo:&quot;</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">arityInfo</span><span> </span><span class="hs-identifier">fn_info</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-491"></span><span>                   </span><span class="annot"><span class="annottext">CprType -&gt; CprResult
</span><a href="GHC.Types.Cpr.html#ct_cpr"><span class="hs-identifier hs-var hs-var">ct_cpr</span></a></span><span> </span><span class="annot"><span class="annottext">CprType
</span><a href="#local-6989586621680963449"><span class="hs-identifier hs-var">cpr_ty</span></a></span><span>
</span><span id="line-492"></span><span>
</span><span id="line-493"></span><span>    </span><span id="local-6989586621680963460"><span class="annot"><span class="annottext">new_fn_id :: Var
</span><a href="#local-6989586621680963460"><span class="hs-identifier hs-var hs-var">new_fn_id</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Var
</span><a href="GHC.Types.Id.html#zapIdUsedOnceInfo"><span class="hs-identifier hs-var">zapIdUsedOnceInfo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Var
</span><a href="GHC.Types.Id.html#zapIdUsageEnvInfo"><span class="hs-identifier hs-var">zapIdUsageEnvInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-494"></span><span>        </span><span class="hs-comment">-- See Note [Zapping DmdEnv after Demand Analyzer] and</span><span>
</span><span id="line-495"></span><span>        </span><span class="hs-comment">-- See Note [Zapping Used Once info WorkWrap]</span><span>
</span><span id="line-496"></span><span>
</span><span id="line-497"></span><span>    </span><span id="local-6989586621680963464"><span class="annot"><span class="annottext">is_fun :: Bool
</span><a href="#local-6989586621680963464"><span class="hs-identifier hs-var hs-var">is_fun</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.Utils.Misc.html#notNull"><span class="hs-identifier hs-var">notNull</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680963459"><span class="hs-identifier hs-var">wrap_dmds</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span><span>
</span><span id="line-498"></span><span>    </span><span class="hs-comment">-- See Note [Don't eta expand in w/w]</span><span>
</span><span id="line-499"></span><span>    </span><span id="local-6989586621680963462"><span class="annot"><span class="annottext">is_eta_exp :: Bool
</span><a href="#local-6989586621680963462"><span class="hs-identifier hs-var hs-var">is_eta_exp</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; ArityInfo
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; ArityInfo
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680963459"><span class="hs-identifier hs-var">wrap_dmds</span></a></span><span> </span><span class="annot"><span class="annottext">ArityInfo -&gt; ArityInfo -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; ArityInfo
</span><a href="GHC.Core.Opt.Arity.html#manifestArity"><span class="hs-identifier hs-var">manifestArity</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-500"></span><span>    </span><span id="local-6989586621680963456"><span class="annot"><span class="annottext">is_thunk :: Bool
</span><a href="#local-6989586621680963456"><span class="hs-identifier hs-var hs-var">is_thunk</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680963464"><span class="hs-identifier hs-var">is_fun</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Var -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsHNF"><span class="hs-identifier hs-var">exprIsHNF</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963468"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-501"></span><span>                            </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Type -&gt; Bool
Type -&gt; Bool
</span><a href="GHC.Core.Type.html#isUnliftedType"><span class="hs-identifier hs-var">isUnliftedType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963469"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-502"></span><span>
</span><span id="line-503"></span><span class="hs-comment">{-
Note [Zapping DmdEnv after Demand Analyzer]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the worker-wrapper pass we zap the DmdEnv.  Why?
 (a) it is never used again
 (b) it wastes space
 (c) it becomes incorrect as things are cloned, because
     we don't push the substitution into it

Why here?
 * Because we don&#8217;t want to do it in the Demand Analyzer, as we never know
   there when we are doing the last pass.
 * We want them to be still there at the end of DmdAnal, so that
   -ddump-str-anal contains them.
 * We don&#8217;t want a second pass just for that.
 * WorkWrap looks at all bindings anyway.

We also need to do it in TidyCore.tidyLetBndr to clean up after the
final, worker/wrapper-less run of the demand analyser (see
Note [Final Demand Analyser run] in GHC.Core.Opt.DmdAnal).

Note [Zapping Used Once info in WorkWrap]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the worker-wrapper pass we zap the used once info in demands and in
strictness signatures.

Why?
 * The simplifier may happen to transform code in a way that invalidates the
   data (see #11731 for an example).
 * It is not used in later passes, up to code generation.

So as the data is useless and possibly wrong, we want to remove it. The most
convenient place to do that is the worker wrapper phase, as it runs after every
run of the demand analyser besides the very last one (which is the one where we
want to _keep_ the info for the code generator).

We do not do it in the demand analyser for the same reasons outlined in
Note [Zapping DmdEnv after Demand Analyzer] above.

Note [Don't eta expand in w/w]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A binding where the manifestArity of the RHS is less than idArity of the binder
means GHC.Core.Opt.Arity didn't eta expand that binding. When this happens, it does so
for a reason (see Note [exprArity invariant] in GHC.Core.Opt.Arity) and we probably have
a PAP, cast or trivial expression as RHS.

Performing the worker/wrapper split will implicitly eta-expand the binding to
idArity, overriding GHC.Core.Opt.Arity's decision. Other than playing fast and loose with
divergence, it's also broken for newtypes:

  f = (\xy.blah) |&gt; co
    where
      co :: (Int -&gt; Int -&gt; Char) ~ T

Then idArity is 2 (despite the type T), and it can have a StrictSig based on a
threshold of 2. But we can't w/w it without a type error.

The situation is less grave for PAPs, but the implicit eta expansion caused a
compiler allocation regression in T15164, where huge recursive instance method
groups, mostly consisting of PAPs, got w/w'd. This caused great churn in the
simplifier, when simply waiting for the PAPs to inline arrived at the same
output program.

Note there is the worry here that such PAPs and trivial RHSs might not *always*
be inlined. That would lead to reboxing, because the analysis tacitly assumes
that we W/W'd for idArity and will propagate analysis information under that
assumption. So far, this doesn't seem to matter in practice.
See https://gitlab.haskell.org/ghc/ghc/merge_requests/312#note_192064.
-}</span><span>
</span><span id="line-572"></span><span>
</span><span id="line-573"></span><span>
</span><span id="line-574"></span><span class="hs-comment">---------------------</span><span>
</span><span id="line-575"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#splitFun"><span class="hs-identifier hs-type">splitFun</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#IdInfo"><span class="hs-identifier hs-type">IdInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Divergence"><span class="hs-identifier hs-type">Divergence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Cpr.html#CprResult"><span class="hs-identifier hs-type">CprResult</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-576"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html#UniqSM"><span class="hs-identifier hs-type">UniqSM</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-577"></span><span id="splitFun"><span class="annot"><span class="annottext">splitFun :: DynFlags
-&gt; FamInstEnvs
-&gt; Var
-&gt; IdInfo
-&gt; [Demand]
-&gt; Divergence
-&gt; CprResult
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#splitFun"><span class="hs-identifier hs-var hs-var">splitFun</span></a></span></span><span> </span><span id="local-6989586621680963415"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963415"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963414"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963414"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621680963413"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963413"><span class="hs-identifier hs-var">fn_id</span></a></span></span><span> </span><span id="local-6989586621680963412"><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963412"><span class="hs-identifier hs-var">fn_info</span></a></span></span><span> </span><span id="local-6989586621680963411"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680963411"><span class="hs-identifier hs-var">wrap_dmds</span></a></span></span><span> </span><span id="local-6989586621680963410"><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680963410"><span class="hs-identifier hs-var">div</span></a></span></span><span> </span><span id="local-6989586621680963409"><span class="annot"><span class="annottext">CprResult
</span><a href="#local-6989586621680963409"><span class="hs-identifier hs-var">cpr</span></a></span></span><span> </span><span id="local-6989586621680963408"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963408"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-578"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WARN</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">wrap_dmds</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">lengthIs</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">arity</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">arity</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">wrap_dmds</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">cpr</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-579"></span><span>    </span><span class="hs-comment">-- The arity should match the signature</span><span>
</span><span id="line-580"></span><span>    </span><span class="hs-identifier">stuff</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mkWwBodies</span><span> </span><span class="hs-identifier">dflags</span><span> </span><span class="hs-identifier">fam_envs</span><span> </span><span class="hs-identifier">rhs_fvs</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-identifier">wrap_dmds</span><span> </span><span class="hs-identifier">use_cpr_info</span><span>
</span><span id="line-581"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">stuff</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-582"></span><span>      </span><span class="hs-identifier">Just</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">work_demands</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">join_arity</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">wrap_fn</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">work_fn</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-583"></span><span>        </span><span class="hs-identifier">work_uniq</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getUniqueM</span><span>
</span><span id="line-584"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">work_rhs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">work_fn</span><span> </span><span class="hs-identifier">rhs</span><span>
</span><span id="line-585"></span><span>            </span><span class="hs-identifier">work_act</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">fn_inline_spec</span><span> </span><span class="hs-keyword">of</span><span>  </span><span class="hs-comment">-- See Note [Worker activation]</span><span>
</span><span id="line-586"></span><span>                          </span><span class="hs-identifier">NoInline</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">inl_act</span><span> </span><span class="hs-identifier">fn_inl_prag</span><span>
</span><span id="line-587"></span><span>                          </span><span class="hs-identifier">_</span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">inl_act</span><span> </span><span class="hs-identifier">wrap_prag</span><span>
</span><span id="line-588"></span><span>
</span><span id="line-589"></span><span>            </span><span class="hs-identifier">work_prag</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">InlinePragma</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">inl_src</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SourceText</span><span> </span><span class="hs-string">&quot;{-# INLINE&quot;</span><span>
</span><span id="line-590"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">inl_inline</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fn_inline_spec</span><span>
</span><span id="line-591"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">inl_sat</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-592"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">inl_act</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">work_act</span><span>
</span><span id="line-593"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">inl_rule</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">FunLike</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-594"></span><span>              </span><span class="hs-comment">-- inl_inline: copy from fn_id; see Note [Worker-wrapper for INLINABLE functions]</span><span>
</span><span id="line-595"></span><span>              </span><span class="hs-comment">-- inl_act:    see Note [Worker activation]</span><span>
</span><span id="line-596"></span><span>              </span><span class="hs-comment">-- inl_rule:   it does not make sense for workers to be constructorlike.</span><span>
</span><span id="line-597"></span><span>
</span><span id="line-598"></span><span>            </span><span class="hs-identifier">work_join_arity</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">isJoinId</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">join_arity</span><span>
</span><span id="line-599"></span><span>                            </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-600"></span><span>              </span><span class="hs-comment">-- worker is join point iff wrapper is join point</span><span>
</span><span id="line-601"></span><span>              </span><span class="hs-comment">-- (see Note [Don't w/w join points for CPR])</span><span>
</span><span id="line-602"></span><span>
</span><span id="line-603"></span><span>            </span><span class="hs-identifier">work_id</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mkWorkerId</span><span> </span><span class="hs-identifier">work_uniq</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">exprType</span><span> </span><span class="hs-identifier">work_rhs</span><span class="hs-special">)</span><span>
</span><span id="line-604"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setIdOccInfo</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">occInfo</span><span> </span><span class="hs-identifier">fn_info</span><span>
</span><span id="line-605"></span><span>                                </span><span class="hs-comment">-- Copy over occurrence info from parent</span><span>
</span><span id="line-606"></span><span>                                </span><span class="hs-comment">-- Notably whether it's a loop breaker</span><span>
</span><span id="line-607"></span><span>                                </span><span class="hs-comment">-- Doesn't matter much, since we will simplify next, but</span><span>
</span><span id="line-608"></span><span>                                </span><span class="hs-comment">-- seems right-er to do so</span><span>
</span><span id="line-609"></span><span>
</span><span id="line-610"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setInlinePragma</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">work_prag</span><span>
</span><span id="line-611"></span><span>
</span><span id="line-612"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setIdUnfolding</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">mkWorkerUnfolding</span><span> </span><span class="hs-identifier">dflags</span><span> </span><span class="hs-identifier">work_fn</span><span> </span><span class="hs-identifier">fn_unfolding</span><span>
</span><span id="line-613"></span><span>                                </span><span class="hs-comment">-- See Note [Worker-wrapper for INLINABLE functions]</span><span>
</span><span id="line-614"></span><span>
</span><span id="line-615"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setIdStrictness</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">mkClosedStrictSig</span><span> </span><span class="hs-identifier">work_demands</span><span> </span><span class="hs-identifier">div</span><span>
</span><span id="line-616"></span><span>                                </span><span class="hs-comment">-- Even though we may not be at top level,</span><span>
</span><span id="line-617"></span><span>                                </span><span class="hs-comment">-- it's ok to give it an empty DmdEnv</span><span>
</span><span id="line-618"></span><span>
</span><span id="line-619"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setIdCprInfo</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">mkCprSig</span><span> </span><span class="hs-identifier">work_arity</span><span> </span><span class="hs-identifier">work_cpr_info</span><span>
</span><span id="line-620"></span><span>
</span><span id="line-621"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setIdDemandInfo</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">worker_demand</span><span>
</span><span id="line-622"></span><span>
</span><span id="line-623"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">setIdArity</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">work_arity</span><span>
</span><span id="line-624"></span><span>                                </span><span class="hs-comment">-- Set the arity so that the Core Lint check that the</span><span>
</span><span id="line-625"></span><span>                                </span><span class="hs-comment">-- arity is consistent with the demand type goes</span><span>
</span><span id="line-626"></span><span>                                </span><span class="hs-comment">-- through</span><span>
</span><span id="line-627"></span><span>                        </span><span class="hs-special">`</span><span class="hs-identifier">asJoinId_maybe</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">work_join_arity</span><span>
</span><span id="line-628"></span><span>
</span><span id="line-629"></span><span>            </span><span class="hs-identifier">work_arity</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">length</span><span> </span><span class="hs-identifier">work_demands</span><span>
</span><span id="line-630"></span><span>
</span><span id="line-631"></span><span>            </span><span class="hs-comment">-- See Note [Demand on the Worker]</span><span>
</span><span id="line-632"></span><span>            </span><span class="hs-identifier">single_call</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">saturatedByOneShots</span><span> </span><span class="hs-identifier">arity</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">demandInfo</span><span> </span><span class="hs-identifier">fn_info</span><span class="hs-special">)</span><span>
</span><span id="line-633"></span><span>            </span><span class="hs-identifier">worker_demand</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">single_call</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mkWorkerDemand</span><span> </span><span class="hs-identifier">work_arity</span><span>
</span><span id="line-634"></span><span>                          </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">topDmd</span><span>
</span><span id="line-635"></span><span>
</span><span id="line-636"></span><span>            </span><span class="hs-identifier">wrap_rhs</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">wrap_fn</span><span> </span><span class="hs-identifier">work_id</span><span>
</span><span id="line-637"></span><span>            </span><span class="hs-identifier">wrap_prag</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mkStrWrapperInlinePrag</span><span> </span><span class="hs-identifier">fn_inl_prag</span><span>
</span><span id="line-638"></span><span>            </span><span class="hs-identifier">wrap_id</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">setIdUnfolding</span><span class="hs-special">`</span><span>  </span><span class="hs-identifier">mkWwInlineRule</span><span> </span><span class="hs-identifier">dflags</span><span> </span><span class="hs-identifier">wrap_rhs</span><span> </span><span class="hs-identifier">arity</span><span>
</span><span id="line-639"></span><span>                              </span><span class="hs-special">`</span><span class="hs-identifier">setInlinePragma</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">wrap_prag</span><span>
</span><span id="line-640"></span><span>                              </span><span class="hs-special">`</span><span class="hs-identifier">setIdOccInfo</span><span class="hs-special">`</span><span>    </span><span class="hs-identifier">noOccInfo</span><span>
</span><span id="line-641"></span><span>                                </span><span class="hs-comment">-- Zap any loop-breaker-ness, to avoid bleating from Lint</span><span>
</span><span id="line-642"></span><span>                                </span><span class="hs-comment">-- about a loop breaker with an INLINE rule</span><span>
</span><span id="line-643"></span><span>
</span><span id="line-644"></span><span>
</span><span id="line-645"></span><span>
</span><span id="line-646"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-identifier">work_id</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">work_rhs</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">wrap_id</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">wrap_rhs</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-647"></span><span>            </span><span class="hs-comment">-- Worker first, because wrapper mentions it</span><span>
</span><span id="line-648"></span><span>
</span><span id="line-649"></span><span>      </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-identifier">fn_id</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">rhs</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-650"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-651"></span><span>    </span><span id="local-6989586621680963401"><span class="annot"><span class="annottext">rhs_fvs :: VarSet
</span><a href="#local-6989586621680963401"><span class="hs-identifier hs-var hs-var">rhs_fvs</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Var -&gt; VarSet
</span><a href="GHC.Core.FVs.html#exprFreeVars"><span class="hs-identifier hs-var">exprFreeVars</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963408"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-652"></span><span>    </span><span id="local-6989586621680963388"><span class="annot"><span class="annottext">fn_inl_prag :: InlinePragma
</span><a href="#local-6989586621680963388"><span class="hs-identifier hs-var hs-var">fn_inl_prag</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; InlinePragma
</span><a href="GHC.Types.Id.Info.html#inlinePragInfo"><span class="hs-identifier hs-var hs-var">inlinePragInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963412"><span class="hs-identifier hs-var">fn_info</span></a></span><span>
</span><span id="line-653"></span><span>    </span><span id="local-6989586621680963391"><span class="annot"><span class="annottext">fn_inline_spec :: InlineSpec
</span><a href="#local-6989586621680963391"><span class="hs-identifier hs-var hs-var">fn_inline_spec</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InlinePragma -&gt; InlineSpec
</span><a href="GHC.Types.Basic.html#inl_inline"><span class="hs-identifier hs-var hs-var">inl_inline</span></a></span><span> </span><span class="annot"><span class="annottext">InlinePragma
</span><a href="#local-6989586621680963388"><span class="hs-identifier hs-var">fn_inl_prag</span></a></span><span>
</span><span id="line-654"></span><span>    </span><span id="local-6989586621680963372"><span class="annot"><span class="annottext">fn_unfolding :: Unfolding
</span><a href="#local-6989586621680963372"><span class="hs-identifier hs-var hs-var">fn_unfolding</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; Unfolding
</span><a href="GHC.Types.Id.Info.html#unfoldingInfo"><span class="hs-identifier hs-var hs-var">unfoldingInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963412"><span class="hs-identifier hs-var">fn_info</span></a></span><span>
</span><span id="line-655"></span><span>    </span><span id="local-6989586621680963405"><span class="annot"><span class="annottext">arity :: ArityInfo
</span><a href="#local-6989586621680963405"><span class="hs-identifier hs-var hs-var">arity</span></a></span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; ArityInfo
</span><a href="GHC.Types.Id.Info.html#arityInfo"><span class="hs-identifier hs-var">arityInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680963412"><span class="hs-identifier hs-var">fn_info</span></a></span><span>
</span><span id="line-656"></span><span>                    </span><span class="hs-comment">-- The arity is set by the simplifier using exprEtaExpandArity</span><span>
</span><span id="line-657"></span><span>                    </span><span class="hs-comment">-- So it may be more than the number of top-level-visible lambdas</span><span>
</span><span id="line-658"></span><span>
</span><span id="line-659"></span><span>    </span><span class="hs-comment">-- use_cpr_info is the CPR we w/w for. Note that we kill it for join points,</span><span>
</span><span id="line-660"></span><span>    </span><span class="hs-comment">-- see Note [Don't w/w join points for CPR].</span><span>
</span><span id="line-661"></span><span>    </span><span id="local-6989586621680963400"><span class="annot"><span class="annottext">use_cpr_info :: CprResult
</span><a href="#local-6989586621680963400"><span class="hs-identifier hs-var hs-var">use_cpr_info</span></a></span></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963413"><span class="hs-identifier hs-var">fn_id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CprResult
</span><a href="GHC.Types.Cpr.html#topCpr"><span class="hs-identifier hs-var">topCpr</span></a></span><span>
</span><span id="line-662"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CprResult
</span><a href="#local-6989586621680963409"><span class="hs-identifier hs-var">cpr</span></a></span><span>
</span><span id="line-663"></span><span>    </span><span class="hs-comment">-- Even if we don't w/w join points for CPR, we might still do so for</span><span>
</span><span id="line-664"></span><span>    </span><span class="hs-comment">-- strictness. In which case a join point worker keeps its original CPR</span><span>
</span><span id="line-665"></span><span>    </span><span class="hs-comment">-- property; see Note [Don't w/w join points for CPR]. Otherwise, the worker</span><span>
</span><span id="line-666"></span><span>    </span><span class="hs-comment">-- doesn't have the CPR property anymore.</span><span>
</span><span id="line-667"></span><span>    </span><span id="local-6989586621680963366"><span class="annot"><span class="annottext">work_cpr_info :: CprResult
</span><a href="#local-6989586621680963366"><span class="hs-identifier hs-var hs-var">work_cpr_info</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963413"><span class="hs-identifier hs-var">fn_id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CprResult
</span><a href="#local-6989586621680963409"><span class="hs-identifier hs-var">cpr</span></a></span><span>
</span><span id="line-668"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CprResult
</span><a href="GHC.Types.Cpr.html#topCpr"><span class="hs-identifier hs-var">topCpr</span></a></span><span>
</span><span id="line-669"></span><span>
</span><span id="line-670"></span><span>
</span><span id="line-671"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#mkStrWrapperInlinePrag"><span class="hs-identifier hs-type">mkStrWrapperInlinePrag</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#InlinePragma"><span class="hs-identifier hs-type">InlinePragma</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#InlinePragma"><span class="hs-identifier hs-type">InlinePragma</span></a></span><span>
</span><span id="line-672"></span><span id="mkStrWrapperInlinePrag"><span class="annot"><span class="annottext">mkStrWrapperInlinePrag :: InlinePragma -&gt; InlinePragma
</span><a href="GHC.Core.Opt.WorkWrap.html#mkStrWrapperInlinePrag"><span class="hs-identifier hs-var hs-var">mkStrWrapperInlinePrag</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Basic.html#InlinePragma"><span class="hs-identifier hs-type">InlinePragma</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">inl_act :: InlinePragma -&gt; Activation
</span><a href="GHC.Types.Basic.html#inl_act"><span class="hs-identifier hs-var">inl_act</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963348"><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963348"><span class="hs-identifier hs-var">act</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">inl_rule :: InlinePragma -&gt; RuleMatchInfo
</span><a href="GHC.Types.Basic.html#inl_rule"><span class="hs-identifier hs-var">inl_rule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680963347"><span class="annot"><span class="annottext">RuleMatchInfo
</span><a href="#local-6989586621680963347"><span class="hs-identifier hs-var">rule_info</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-673"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InlinePragma :: SourceText
-&gt; InlineSpec
-&gt; Maybe ArityInfo
-&gt; Activation
-&gt; RuleMatchInfo
-&gt; InlinePragma
</span><a href="GHC.Types.Basic.html#InlinePragma"><span class="hs-identifier hs-type">InlinePragma</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">inl_src :: SourceText
</span><a href="GHC.Types.Basic.html#inl_src"><span class="hs-identifier hs-var">inl_src</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SourceText
</span><a href="GHC.Types.Basic.html#SourceText"><span class="hs-identifier hs-var">SourceText</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;{-# INLINE&quot;</span></span><span>
</span><span id="line-674"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">inl_inline :: InlineSpec
</span><a href="GHC.Types.Basic.html#inl_inline"><span class="hs-identifier hs-var">inl_inline</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InlineSpec
</span><a href="GHC.Types.Basic.html#NoUserInline"><span class="hs-identifier hs-var">NoUserInline</span></a></span><span> </span><span class="hs-comment">-- See Note [Wrapper NoUserInline]</span><span>
</span><span id="line-675"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">inl_sat :: Maybe ArityInfo
</span><a href="GHC.Types.Basic.html#inl_sat"><span class="hs-identifier hs-var">inl_sat</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe ArityInfo
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-676"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">inl_act :: Activation
</span><a href="GHC.Types.Basic.html#inl_act"><span class="hs-identifier hs-var">inl_act</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963345"><span class="hs-identifier hs-var">wrap_act</span></a></span><span>
</span><span id="line-677"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">inl_rule :: RuleMatchInfo
</span><a href="GHC.Types.Basic.html#inl_rule"><span class="hs-identifier hs-var">inl_rule</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleMatchInfo
</span><a href="#local-6989586621680963347"><span class="hs-identifier hs-var">rule_info</span></a></span><span> </span><span class="hs-special">}</span><span>  </span><span class="hs-comment">-- RuleMatchInfo is (and must be) unaffected</span><span>
</span><span id="line-678"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-679"></span><span>    </span><span id="local-6989586621680963345"><span class="annot"><span class="annottext">wrap_act :: Activation
</span><a href="#local-6989586621680963345"><span class="hs-identifier hs-var hs-var">wrap_act</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963348"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="hs-keyword">of</span><span>  </span><span class="hs-comment">-- See Note [Wrapper activation]</span><span>
</span><span id="line-680"></span><span>                   </span><span class="annot"><span class="annottext">Activation
</span><a href="GHC.Types.Basic.html#NeverActive"><span class="hs-identifier hs-var">NeverActive</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="GHC.Types.Basic.html#activateDuringFinal"><span class="hs-identifier hs-var">activateDuringFinal</span></a></span><span>
</span><span id="line-681"></span><span>                   </span><span class="annot"><span class="annottext">Activation
</span><a href="GHC.Types.Basic.html#FinalActive"><span class="hs-identifier hs-var">FinalActive</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963348"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-682"></span><span>                   </span><span class="annot"><a href="GHC.Types.Basic.html#ActiveAfter"><span class="hs-identifier hs-type">ActiveAfter</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680963348"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-683"></span><span>                   </span><span class="annot"><a href="GHC.Types.Basic.html#ActiveBefore"><span class="hs-identifier hs-type">ActiveBefore</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="GHC.Types.Basic.html#activateAfterInitial"><span class="hs-identifier hs-var">activateAfterInitial</span></a></span><span>
</span><span id="line-684"></span><span>                   </span><span class="annot"><span class="annottext">Activation
</span><a href="GHC.Types.Basic.html#AlwaysActive"><span class="hs-identifier hs-var">AlwaysActive</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="GHC.Types.Basic.html#activateAfterInitial"><span class="hs-identifier hs-var">activateAfterInitial</span></a></span><span>
</span><span id="line-685"></span><span>      </span><span class="hs-comment">-- For the last two cases, see (4) in Note [Wrapper activation]</span><span>
</span><span id="line-686"></span><span>      </span><span class="hs-comment">-- NB: the (ActiveBefore n) isn't quite right. We really want</span><span>
</span><span id="line-687"></span><span>      </span><span class="hs-comment">-- it to be active *after* Initial but *before* n.  We don't have</span><span>
</span><span id="line-688"></span><span>      </span><span class="hs-comment">-- a way to say that, alas.</span><span>
</span><span id="line-689"></span><span>
</span><span id="line-690"></span><span class="hs-comment">{-
Note [Demand on the worker]
~~~~~~~~~~~~~~~~~~~~~~~~~~~

If the original function is called once, according to its demand info, then
so is the worker. This is important so that the occurrence analyser can
attach OneShot annotations to the worker&#8217;s lambda binders.


Example:

  -- Original function
  f [Demand=&lt;L,1*C1(U)&gt;] :: (a,a) -&gt; a
  f = \p -&gt; ...

  -- Wrapper
  f [Demand=&lt;L,1*C1(U)&gt;] :: a -&gt; a -&gt; a
  f = \p -&gt; case p of (a,b) -&gt; $wf a b

  -- Worker
  $wf [Demand=&lt;L,1*C1(C1(U))&gt;] :: Int -&gt; Int
  $wf = \a b -&gt; ...

We need to check whether the original function is called once, with
sufficiently many arguments. This is done using saturatedByOneShots, which
takes the arity of the original function (resp. the wrapper) and the demand on
the original function.

The demand on the worker is then calculated using mkWorkerDemand, and always of
the form [Demand=&lt;L,1*(C1(...(C1(U))))&gt;]


Note [Do not split void functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this rather common form of binding:
        $j = \x:Void# -&gt; ...no use of x...

Since x is not used it'll be marked as absent.  But there is no point
in w/w-ing because we'll simply add (\y:Void#), see GHC.Core.Opt.WorkWrap.Utils.mkWorerArgs.

If x has a more interesting type (eg Int, or Int#), there *is* a point
in w/w so that we don't pass the argument at all.

Note [Thunk splitting]
~~~~~~~~~~~~~~~~~~~~~~
Suppose x is used strictly (never mind whether it has the CPR
property).

      let
        x* = x-rhs
      in body

splitThunk transforms like this:

      let
        x* = case x-rhs of { I# a -&gt; I# a }
      in body

Now simplifier will transform to

      case x-rhs of
        I# a -&gt; let x* = I# a
                in body

which is what we want. Now suppose x-rhs is itself a case:

        x-rhs = case e of { T -&gt; I# a; F -&gt; I# b }

The join point will abstract over a, rather than over (which is
what would have happened before) which is fine.

Notice that x certainly has the CPR property now!

In fact, splitThunk uses the function argument w/w splitting
function, so that if x's demand is deeper (say U(U(L,L),L))
then the splitting will go deeper too.
-}</span><span>
</span><span id="line-767"></span><span>
</span><span id="line-768"></span><span class="hs-comment">-- See Note [Thunk splitting]</span><span>
</span><span id="line-769"></span><span class="hs-comment">-- splitThunk converts the *non-recursive* binding</span><span>
</span><span id="line-770"></span><span class="hs-comment">--      x = e</span><span>
</span><span id="line-771"></span><span class="hs-comment">-- into</span><span>
</span><span id="line-772"></span><span class="hs-comment">--      x = let x = e</span><span>
</span><span id="line-773"></span><span class="hs-comment">--          in case x of</span><span>
</span><span id="line-774"></span><span class="hs-comment">--               I# y -&gt; let x = I# y in x }</span><span>
</span><span id="line-775"></span><span class="hs-comment">-- See comments above. Is it not beautifully short?</span><span>
</span><span id="line-776"></span><span class="hs-comment">-- Moreover, it works just as well when there are</span><span>
</span><span id="line-777"></span><span class="hs-comment">-- several binders, and if the binders are lifted</span><span>
</span><span id="line-778"></span><span class="hs-comment">-- E.g.     x = e</span><span>
</span><span id="line-779"></span><span class="hs-comment">--     --&gt;  x = let x = e in</span><span>
</span><span id="line-780"></span><span class="hs-comment">--              case x of (a,b) -&gt; let x = (a,b)  in x</span><span>
</span><span id="line-781"></span><span>
</span><span id="line-782"></span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.html#splitThunk"><span class="hs-identifier hs-type">splitThunk</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#RecFlag"><span class="hs-identifier hs-type">RecFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Expr"><span class="hs-identifier hs-type">Expr</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Supply.html#UniqSM"><span class="hs-identifier hs-type">UniqSM</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#Expr"><span class="hs-identifier hs-type">Expr</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-783"></span><span id="splitThunk"><span class="annot"><span class="annottext">splitThunk :: DynFlags
-&gt; FamInstEnvs
-&gt; RecFlag
-&gt; Var
-&gt; Expr Var
-&gt; UniqSM [(Var, Expr Var)]
</span><a href="GHC.Core.Opt.WorkWrap.html#splitThunk"><span class="hs-identifier hs-var hs-var">splitThunk</span></a></span></span><span> </span><span id="local-6989586621680963337"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963337"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680963336"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963336"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621680963335"><span class="annot"><span class="annottext">RecFlag
</span><a href="#local-6989586621680963335"><span class="hs-identifier hs-var">is_rec</span></a></span></span><span> </span><span id="local-6989586621680963334"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963334"><span class="hs-identifier hs-var">fn_id</span></a></span></span><span> </span><span id="local-6989586621680963333"><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963333"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-784"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">isJoinId</span><span> </span><span class="hs-identifier">fn_id</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-785"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680963331"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680963331"><span class="hs-identifier hs-var">useful</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Var]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680963330"><span class="annot"><span class="annottext">Expr Var -&gt; Expr Var
</span><a href="#local-6989586621680963330"><span class="hs-identifier hs-var">wrap_fn</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680963329"><span class="annot"><span class="annottext">Expr Var -&gt; Expr Var
</span><a href="#local-6989586621680963329"><span class="hs-identifier hs-var">work_fn</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; FamInstEnvs
-&gt; Bool
-&gt; [Var]
-&gt; UniqSM (Bool, [Var], Expr Var -&gt; Expr Var, Expr Var -&gt; Expr Var)
</span><a href="GHC.Core.Opt.WorkWrap.Utils.html#mkWWstr"><span class="hs-identifier hs-var">mkWWstr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680963337"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680963336"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963334"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-786"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680963327"><span class="annot"><span class="annottext">res :: [(Var, Expr Var)]
</span><a href="#local-6989586621680963327"><span class="hs-identifier hs-var hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963334"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; Expr Var -&gt; Expr Var
forall b. Bind b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Let"><span class="hs-identifier hs-var">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Expr Var -&gt; CoreBind
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963334"><span class="hs-identifier hs-var">fn_id</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963333"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Var -&gt; Expr Var
</span><a href="#local-6989586621680963330"><span class="hs-identifier hs-var">wrap_fn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Var -&gt; Expr Var
</span><a href="#local-6989586621680963329"><span class="hs-identifier hs-var">work_fn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Expr Var
forall b. Var -&gt; Expr b
</span><a href="GHC.Core.html#Var"><span class="hs-identifier hs-var">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963334"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-787"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680963331"><span class="hs-identifier hs-var">useful</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isNonRec</span><span> </span><span class="hs-identifier">is_rec</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">fn_id</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- The thunk must be non-recursive</span><span>
</span><span id="line-788"></span><span>                   </span><span class="annot"><span class="annottext">[(Var, Expr Var)] -&gt; UniqSM [(Var, Expr Var)]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)]
</span><a href="#local-6989586621680963327"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-789"></span><span>                   </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">[(Var, Expr Var)] -&gt; UniqSM [(Var, Expr Var)]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680963334"><span class="hs-identifier hs-var">fn_id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Var
</span><a href="#local-6989586621680963333"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-790"></span></pre></body></html>